<template>
  <view class="hot-comtainer">
    <navigator :url="`/pages/category/goodsDetail?id=${item.id_}`" class="spu_goods" v-for="item in list" :key="item.id_">
      <image class="spu_goods_img" :src="item.main_img_" mode="aspectFill" />
      <view class="spu_goods_name ellipsis">{{ item.name_ }}</view>
      <view class="spu_goods_footer">
        <text class="spu_goods_price">￥{{ item.price_ }}</text>
        <view class="icon-cart-container" @tap.stop="checkSpec(item)">
          <text class="iconfont icon-cart"></text>
        </view>
      </view>
    </navigator>
  </view>
</template>

<script setup lang="ts">
import { onMounted, ref } from "vue"
import type { goodsSpuData, floorsState } from '@/types/home';
import Apis from "@/services/modules/home"

const props = defineProps<{
  hotParams: floorsState
}>()

const emits = defineEmits(['showSkuPanel'])

const list = ref<goodsSpuData[]>()

onMounted(() => {
  searchListForDecorateData()
})

const searchListForDecorateData = async () => {
  const { data } = await Apis.searchListForDecorateApi({
    ...props.hotParams.setting_
  })

  list.value = data.pdList
}

defineExpose({
  getMore: searchListForDecorateData
})

const checkSpec = async (item: goodsSpuData) => {
  emits('showSkuPanel', item.id_)
}

</script>

<style lang="scss">
page {
  position: relative;
}

.hot-comtainer {
  margin-top: 16px;
  padding: 0 6px;
  display: flex;
  flex-wrap: wrap;

  .spu_goods {
    width: calc(50% - 6px);
    margin-bottom: 12px;
    background-color: #fff;

    &:nth-child(2n + 1) {
      margin-right: 12px;
    }

    .spu_goods_img {
      width: 100%;
      height: 188px;
    }

    .spu_goods_name {
      $padding: 4px;
      padding: 0 $padding ;
      width: calc(100% - 2 * $padding);
      font-size: 14px;
    }

    .spu_goods_footer {
      display: flex;
      justify-content: space-between;
      align-items: center;
      padding: 4px;

      .spu_goods_price {
        color: red;
        font-size: 18px;
      }

      .icon-cart-container {
        $wh: 30px;
        width: $wh;
        height: $wh;
        border-radius: 50%;
        display: flex;
        justify-content: center;
        align-items: center;
        background-color: $uni-color-warning;

        .icon-cart {
          color: #fff;
          // font-size: 20px;
          // font-weight: bold;
        }
      }
    }
  }
}
</style>

